import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

export const constantRoutes = [
  {
    path: "/",
    redirect: "/index",
  },
  {
    path: "/index",
    component: () =>
      import(/* webpackChunkName: "about" */ "@/views/home/first.vue"),
    name: "首页",
    meta: { title: "首页" },
  },
  {
    path: "/home",
    component: () =>
      import(/* webpackChunkName: "about" */ "@/views/home/index.vue"),
    name: "植树认捐",
    meta: { title: "植树认捐" },
  },
  {
    path: "/donate",
    component: () =>
      import(/* webpackChunkName: "about" */ "@/views/home/donate.vue"),
    name: "认捐信息",
    meta: { title: "认捐信息" },
  },

  {
    path: "/404",
    component: (resolve) => require(["@/views/error/404"], resolve),
    hidden: true,
  },
  { path: "*", redirect: "/404", hidden: true },
];

const createRouter = () =>
  new Router({
    mode: 'history', // require service support
    base: "/h5/",
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  });

const router = createRouter();

export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
